% rm_face_or_back 
% Chris Whalen
% University of Illinois
% 06/15/05 - Date of Birth
% 06/15/05 - Date of Last Modification

% rm_face_or_back - to remove the face or the back of head points from the
% elp file to compensate for the subject lying supine in the magnet.


function [test,choice] = rm_face_or_back(test,choice)




    
choice.rm_pts=input('\nRemove Points?\n1 - Face\n2 - Back of Head\n3 - Both\n4 - None\n');
range = max(test(:,2))-test(1,2);
init_test_size = size(test,1);



if (choice.rm_pts==1) | (choice.rm_pts==3)
    fprintf('\nEnter Face Threshold Fraction:\n(Threshold Fraction is the fraction of the distance from the nasion of the\nelp point to the most posterior elp point from which to remove anterior points.)\n'); % (threshold fraction of zero is keeping all points. threshold fraction of 1 is removal of all points. threshold of 0.30 (default) is removing the points lying in the posterior 30% of the scalp)\n'); 
    thresh_fraction = input('','s');
    if strcmp(thresh_fraction,'') ==1
      thresh_fraction = 0.10; % Default Value. 
    else
      thresh_fraction = str2num(thresh_fraction);
    end
    test = sortrows(test,2);
    thresh_plane_AP = test(1,2) + range*thresh_fraction;
    index = find(test(:,2)<=thresh_plane_AP);
    test = test(index(1):size(test,1),:);
    %test = test(1:429,:);
end
if choice.rm_pts==2 | choice.rm_pts==3
    fprintf('\nEnter Back of Head Threshold Fraction:\n(Threshold Fraction is the fraction of the distance from the most posterior\nelp point to the nasion elp point from which to remove posterior points.)\n'); % (threshold fraction of zero is keeping all points. threshold fraction of 1 is removal of all points. threshold of 0.30 (default) is removing the points lying in the posterior 30% of the scalp)\n'); 
    thresh_fraction = input('','s');
    if strcmp(thresh_fraction,'') ==1
      thresh_fraction = 0.30; % Default Value. Removing the most posterior 3/10 pts
    else
      thresh_fraction = str2num(thresh_fraction);
    end
    test = sortrows(test,2);
    thresh_plane_AP = test(1,2) + range*(1-thresh_fraction); % defining plane
    index = find(test(:,2)>=thresh_plane_AP);
    test = test(1:index(1),:);
end

fin_test_size = size(test,1);
percent_rm = 100*(init_test_size - fin_test_size)/init_test_size;
fprintf('\nNumber of Points Removed: %3.0f (%2.0f%%)\n\n', init_test_size - fin_test_size, percent_rm);



